﻿#E:\Py\Python33\python.exe

# Программа для импорта документов из базы данных OPENERP на sa-pc265
# в базу данных на sa-serv8

import postgresql

db_old_production = postgresql.open("pq://openpg:openpgpwd@sa-pc265/production")

db_old_test = postgresql.open("pq://openpg:openpgpwd@sa-pc265/test")

db_new_test = postgresql.open("pq://palo:palo@sa-serv8/test")

db_new_oldbase = postgresql.open("pq://palo:palo@sa-serv8/oldbase")






#1 - Импорт таблицы res_partner в таблицу res_partner

#2 - Импорт таблицы res_partner_address в таблицу res_partner

#3 - Импорт таблицы res_users в таблицу res_partner

#4 - Импорт таблицы hr_department в таблицу hr_department

#5 - Импорт таблицы res_users в таблицу res_users

#6 - Импорт таблицы resource_resource в таблицу resource_resource

#7 - Импорт таблицы hr_employee в таблицу hr_employee

#8 - Импорт таблицы account_analytic_account в таблицу account_analytic_account


----



#1 - Импорт таблицы подразделений

db_old_production_hr_department = db_old_production.prepare("SELECT id, create_uid, create_date, name FROM hr_department")

insert_into_db_new_oldbase_hr_department = db_new_oldbase.prepare("INSERT INTO hr_department(id, create_uid, create_date, name) VALUES ($1, $2, $3, $4)")

insert_into_db_new_oldbase_hr_department.load_rows(db_old_production_hr_department())

#2 - Импорт таблицы пользователей

db_old_production_res_users = db_old_production.prepare("SELECT id, active, login, password, company_id, 1 as partner_id, create_uid, create_date, write_date, write_uid, menu_id, date as login_date, signature, action_id, 1 AS alias_id FROM res_users WHERE id NOT IN(1)")

insert_into_db_new_oldbase_res_users = db_new_oldbase.prepare("INSERT INTO res_users(id, active, login, password, company_id, partner_id, create_uid, create_date, write_date, write_uid, menu_id, login_date, signature, action_id, alias_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)")

insert_into_db_new_oldbase_res_users.load_rows(db_old_production_res_users())

#3 - Импорт таблицы контрагентов

db_old_production_res_partner = db_old_production.prepare("SELECT id, name, lang, company_id, create_uid, create_date, write_date, write_uid, comment, ean13, color, active, supplier, user_id, title, parent_id, employee, vat,  website, credit_limit, date, customer, ref, 'comment' AS notification_email_send,  x_1s_sc133_code FROM res_partner WHERE id NOT IN (1, 3, 4)")

insert_into_db_new_oldbase_res_partner = db_new_oldbase.prepare("INSERT INTO res_partner(id, name, lang, company_id, create_uid, create_date, write_date, write_uid, comment, ean13, color, active, supplier, user_id, title, parent_id, employee, vat, website, credit_limit, date, customer, ref, notification_email_send, x_1s_sc133_code) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25)")

insert_into_db_new_oldbase_res_partner.load_rows(db_old_production_res_partner())

#4 - Импорт таблицы документов

db_old_production_ir_attachment = db_old_production.prepare("SELECT id, create_uid, create_date, write_date, write_uid, description, datas_fname, url, res_model, company_id, res_name, type, res_id, file_size, db_datas, store_fname, name, file_type, partner_id, user_id, parent_id, index_content, x_date, x_division, x_kind, x_number FROM ir_attachment")

insert_into_db_new_oldbase_ir_attachment = db_new_oldbase.prepare("INSERT INTO ir_attachment(id, create_uid, create_date, write_date, write_uid, description, datas_fname, url, res_model, company_id, res_name, type, res_id, file_size, db_datas, store_fname, name, file_type, partner_id, user_id, parent_id, index_content, x_date, x_division, x_kind, x_number) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)")

insert_into_db_new_oldbase_ir_attachment.load_rows(db_old_production_ir_attachment())

exit()